package com.klod.news.data.api

import com.klod.news.base.BaseResponse
import com.klod.news.config.AppConfig
import com.klod.news.data.KtorClient
import com.klod.news.data.NetworkResult
import com.klod.news.data.bean.*
import kotlinx.coroutines.flow.Flow
import org.koin.core.annotation.Single


interface HomeApi {
    suspend fun getHomeBanner(): Flow<NetworkResult<MutableList<BannerBean>>>
    suspend fun getNewsType(): Flow<NetworkResult<MutableList<NewsTypeBean>>>
    suspend fun getHomeNewsList(page:Int,pageSize:Int): BaseResponse<MutableList<NewsDetailBean>>
    suspend fun getNewsDetail(): Flow<NetworkResult<NewsDetailBean>>
}

@Single
class  KtorHomeApi : HomeApi{

    private val bannerUrl  = AppConfig.BASE_URL+"home/BannerList"
    private val newsTypeUrl  = AppConfig.BASE_URL+"news/type"
    private val newsDetailUrl  = AppConfig.BASE_URL+"news/detail"
    private val newsListUrl  = AppConfig.BASE_URL+"news/list"
    override suspend fun getHomeBanner(): Flow<NetworkResult<MutableList<BannerBean>>> {
        val map = mutableMapOf<String, Any>()
//        map["id"] = orderId
//        map["status"] = orderState
        return KtorClient.requestGet<MutableList<BannerBean>>(bannerUrl, map)

    }

    override suspend fun getNewsType(): Flow<NetworkResult<MutableList<NewsTypeBean>>> {
        val map = mutableMapOf<String, Any>()
//        map["id"] = orderId
//        map["status"] = orderState
        return KtorClient.requestGet<MutableList<NewsTypeBean>>(newsTypeUrl, map)

    }

    //获取新闻详情
    override suspend fun getNewsDetail(): Flow<NetworkResult<NewsDetailBean>> {
        val map = mutableMapOf<String, Any>()
//        map["id"] = orderId
//        map["status"] = orderState
        return KtorClient.requestGet<NewsDetailBean>(newsDetailUrl, map)

    }
    //获取新闻列表
    override suspend fun getHomeNewsList(page:Int,pageSize:Int): BaseResponse<MutableList<NewsDetailBean>> {

        val map = mutableMapOf<String, Any>()
        map["page"] = page
        map["pageSize"] = pageSize
        return KtorClient.requestGetList<MutableList<NewsDetailBean>>(newsListUrl, map)

    }


}